package com.example.erp;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.vectorstore.QuestionAnswerAdvisor;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;

public class RagController {
	@Autowired
	private ChatClient dashscopechatclient;
	@Autowired
	private VectorStore vectorStore;

	@GetMapping(value = "/chat", produces = "text/plain; charset=UTF-8")
	public String generation(String userInput) {
		// 发起聊天请求并处理响应
		// 创建QuestionAnswerAdvisor实例
		QuestionAnswerAdvisor questionAnswerAdvisor = new QuestionAnswerAdvisor(vectorStore);
		return dashscopechatclient
				.prompt()
				.user(userInput)
				.advisors(questionAnswerAdvisor)
				.call()
				.content();
	}
}
